<template>
    <div class="default-main ba-table-box">


        <!-- 表格顶部菜单 -->
        <!-- 自定义按钮请使用插槽，甚至公共搜索也可以使用具名插槽渲染，参见文档 -->
        <TableHeader :buttons="['add', 'delete', 'quickSearch', 'columnDisplay']" :quick-search-placeholder="t('搜索')">
            
        </TableHeader>

        <!-- 表格 -->
        <!-- 表格列有多种自定义渲染方式，比如自定义组件、具名插槽等，参见文档 -->
        <!-- 要使用 el-table 组件原有的属性，直接加在 Table 标签上即可 -->
        
        <Table ref="tableRef">


            <template #type>
                <el-table-column :label="t('类型')" align="center">
                    <template #default="scope">
                        <el-tag v-if="scope.row.type == 1" type="primary">USD >> CNY</el-tag>
                        <el-tag v-if="scope.row.type == 2" type="primary">USD >> KRW</el-tag>
                        <el-tag v-if="scope.row.type == 3" type="primary">CNY >> KRW</el-tag>
                    </template>
                </el-table-column>
            </template>
            
            
        </Table>

        <!-- 表单 -->
        <PopupForm />


    </div>
    
</template>

<script setup lang="ts">
import { ref, provide, onMounted, reactive } from 'vue'
import baTableClass from '/@/utils/baTable'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'

import { exportLanguageApi } from '/@/api/most/system/translate'



defineOptions({
    name: 'system/translate/index',
})

const { t } = useI18n()
const tableRef = ref()


const drawer = ref(false)

const state = reactive({
    
});




let optButtons = defaultOptButtons([])


// 自定义一个新的按钮
let newButton: OptButton[] = [
    {
        render: 'basicButton', // 渲染方式:tipButton=带tip的按钮,confirmButton=带确认框的按钮,moveButton=移动按钮
        name: 'edit',
        title: 'edit',
        text: t('编辑'),
        type: 'primary',
        class: 'btn btn-primary',
        icon: '',
    },{
        render: 'confirmButton',
        name: 'delete',
        title: '',
        text: t('删除'),
        type: 'danger',
        class: 'btn btn-danger mt-0',
        icon: '',
        popconfirm: {
            confirmButtonText: t('删除'),
            cancelButtonText: t('取消'),
            confirmButtonType: 'danger',
            title: t('确定要删除这条记录吗') + '?',
        }
    }
]

// 新按钮合入到默认的按钮数组
optButtons = newButton.concat(optButtons)




/**
 * baTable 内包含了表格的所有数据且数据具备响应性，然后通过 provide 注入给了后代组件
 */
const baTable = new baTableClass(
    new baTableApi('/system/system.Exchange/'),
    {
        pk: 'id',
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('日期'), prop: 'date', align: 'center', operator: 'LIKE', sortable: false },
            { label: t('名称'), prop: 'name', align: 'center', operator: 'LIKE', sortable: false },
            { label: t('汇率'), prop: 'mSellPri', align: 'center', operator: 'LIKE', sortable: false },
            // { label: t('类型'), prop: 'type', align: 'center', operator: 'LIKE', sortable: false, render: 'slot', slotName: 'type' },
            { label: t('操作'), align: 'center', render: 'buttons', buttons: optButtons, operator: false, width: 180 },
        ],
        dblClickNotEditColumn: ['all'],
        defaultOrder: { prop: 'id', order: 'desc' },
    },
    {
        defaultItems: {  },
    },{
        
    },{
        
    }
)

provide('baTable', baTable)

onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.mount()
    baTable.getIndex()?.then(() => {
        baTable.initSort()
        baTable.dragSort()
    })
})
</script>

<style scoped lang="scss">

</style>
